package com.hospital.serviceImpl;

import com.hospital.dao.PatientMapper;
import com.hospital.entity.FollowUpGroup;
import com.hospital.entity.Patient;
import com.hospital.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 患者操作 Service层
 */
@Service
@Transactional
public class PatientServiceImpl implements PatientService {
    @Autowired
    private PatientMapper patientMapper;

    /**
     * 查所有随访组对应的患者
     *
     * @param page    当前页
     * @param pageNum 每页显示条数
     * @param status  随访状态
     * @return 集合中的患者信息
     */
    @Override
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public List<Patient> SelectAll(Integer page, Integer pageNum, String status) {
        List<Patient> patients = patientMapper.SelectAll(page, pageNum, status);
        return patients;
    }

    /**
     * 查所有患者数量
     *
     * @param status 随访状态
     * @return 患者数量
     */
    @Override
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public Integer SelectAllCounts(String status) {
        Integer count = patientMapper.SelectAllCounts(status);
        return count;
    }

    /**
     * 条件查询
     *
     * @param page          当前页
     * @param pageNum       每页显示条数
     * @param followUpGroup 随访组对象
     * @param patient       患者对象
     * @return 集合中的患者信息
     */
    @Override
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public List<Patient> SelectLike(Integer page, Integer pageNum, FollowUpGroup followUpGroup, Patient patient) {
        List<Patient> patients = patientMapper.SelectLike(page, pageNum, followUpGroup, patient);
        return patients;
    }

    /**
     * 条件查询数量
     *
     * @param followUpGroup 随访组对象
     * @param patient       患者对象
     * @return 条件查询的数量
     */
    @Override
    public Integer SelectLikeCount(FollowUpGroup followUpGroup, Patient patient) {
        Integer count = patientMapper.SelectLikeCount(followUpGroup, patient);
        return count;
    }

    /**
     * 查一个患者信息
     *
     * @param id 患者primary key
     * @return 患者信息
     */
    @Override
    public Patient SelectById(Integer id) {
        Patient patient = patientMapper.SelectById(id);
        return patient;
    }

    /**
     * 修改患者信息
     *
     * @param patient 患者对象
     * @return 修改状态
     */
    @Override
    public Integer Update(Patient patient) {
        Integer state = patientMapper.Update(patient);
        return state;
    }

    /**
     * 删除患者方法
     *
     * @param id 患者id
     * @return 删除状态
     */
    @Override
    public Integer Delete(Integer id) {
        Integer state = patientMapper.Delete(id);
        return state;
    }
}
